import requests
import os
import time


filename = input('filename:')
uploadUrl = 'http://127.0.0.1:5000/upload'


def uploadFile(filename, uploadUrl):
    # 上传文件到服务器
    file = {'file': open(filename, 'rb')}
    r = requests.post(uploadUrl, files=file)
    fileRes = r.text  # 获取文件内容
    # -------------------------
    # 处理文件夹
    # basepath = os.path.join(os.path.dirname(__file__), r'download\\')
    # print('basepath==>'+basepath)  #basepath是指桌面路径+download文件夹

    # 上传文件的同一个目录
    basepath = os.path.split(filename)[0]
    print('basepath==>'+basepath)
    # ----------------------
    # 同一个目录下的srt文件
    filename_srt = os.path.splitext(filename)[0]+'.srt'
    print('filename_srt==>'+filename_srt)
    with open(filename_srt,'w', encoding='utf-8') as f:  # 保存文件
    # with open(os.path.join(basepath, filename_srt),'w') as f: # 保存文件
        print('开始写数据啦')
        f.write(fileRes)

uploadFile(filename, uploadUrl)
